using System;
using System.Collections.Generic;
using System.Xml;
using MEA.AE_Data;

namespace MEA.AE_BusinessLogic
{
	public class Xml_LogRecMan : Xml_Log
	{
		public void DatLogCfg_Save(XmlWriter writer, DatLogCfg cfg, string AB)
		{
			writer.WriteComment("RecMan Config ECU " + AB);
			writer.WriteStartElement("RECMAN_DATLOG_CFG", AB);
			writer.WriteStartElement("REC_INTERVAL");
			writer.WriteValue(cfg.RecordInterval);
			writer.WriteEndElement();
			writer.WriteStartElement("CHANNELS");
			for (int i = 0; i < cfg.ChannelSignals.Count; i++)
			{
				byte[] array = cfg.ChannelSignals[i];
				writer.WriteStartElement("CHANNEL");
				writer.WriteAttributeString("ID", (i + 1).ToString());
				writer.WriteAttributeString("HIGHBYTE", string.Format("0x{0:X2}", array[0]));
				writer.WriteAttributeString("LOWBYTE", string.Format("0x{0:X2}", array[1]));
				writer.WriteEndElement();
			}
			writer.WriteEndElement();
			writer.WriteEndElement();
		}

		public DatLogCfg DatLogCfw_Load(XmlReader reader, string AB)
		{
			uint num = 0u;
			List<byte[]> list = new List<byte[]>();
			reader.ReadToFollowing("RECMAN_DATLOG_CFG", AB);
			num = Convert.ToUInt32(ReadGenericValue(reader, "REC_INTERVAL", AB));
			reader.ReadToFollowing("CHANNELS", AB);
			XmlReader xmlReader = reader.ReadSubtree();
			while (xmlReader.ReadToFollowing("CHANNEL"))
			{
				byte[] array = new byte[2];
				xmlReader.ReadAttributeValue();
				reader.ReadToFollowing("CHANNEL");
				reader.ReadAttributeValue();
				reader.ReadContentAsInt();
				reader.ReadAttributeValue();
				array[0] = Convert.ToByte(reader.ReadContentAsString().PadLeft(2));
				reader.ReadAttributeValue();
				array[1] = Convert.ToByte(reader.ReadContentAsString().PadLeft(2));
				list.Add(array);
			}
			return new DatLogCfg(num, list);
		}
	}
}
